package com.springboot.shanhexin.service;

import com.springboot.shanhexin.dao.qiantaiDao;
import com.springboot.shanhexin.entity.hotel;
import com.springboot.shanhexin.entity.place;
import com.springboot.shanhexin.entity.restaurant;
import com.springboot.shanhexin.entity.tourist;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class qiantaiService {

    @Autowired
    private qiantaiDao qiantaiDao;

    //获取景区内所有景点经纬度及id
    public List<place> getallplace(String name) {
        return qiantaiDao.getallplace(name);
    }

    //获取某个景点的所有信息
    public List<place> getplaceone(int id) {
        return qiantaiDao.getplaceone(id);
    }

    //获取某个景点附近的餐厅
    public List<restaurant> getresone(int pid) {
        return qiantaiDao.getresone(pid);
    }

    //获取某个景点附近的旅店
    public List<hotel> getholone(int pid) {
        return qiantaiDao.getholone(pid);
    }

    //查找是否存在该用户
    public int getuserCount(String openid) {
        return qiantaiDao.getuserCount(openid);
    }

    //添加用户
    public void adduseropenid(String openid) {
        qiantaiDao.adduseropenid(openid);
    }

    //更新用户name
    public void addusername(String name,String openid) {
        qiantaiDao.addusername(name,openid);
    }

    //获取路线tid
    public int searchtid(String uid,String title,String my_rode) {
        return qiantaiDao.searchtid(uid,title,my_rode);
    }

    //查找是否存在该路线
    public int gettouristCount(String uid,String title,String my_rode) {
        return qiantaiDao.gettouristCount(uid,title,my_rode);
    }

    //获取openid对应的所有我的路线
    public List<tourist> getalltourist(String uid) {
        return qiantaiDao.getalltourist(uid);
    }

    //获取openid对应的一个我的路线
    public List<tourist> getonetourist(String uid,String title) {
        return qiantaiDao.getonetourist(uid,title);
    }

    //添加我的路线
    public void addtourist(String uid,String title,String my_rode) {
        qiantaiDao.addtourist(uid,title,my_rode);
    }

    //查找是否存在该餐厅
    public int getmy_resCount(int tid,String name,int rid) {
        return qiantaiDao.getmy_resCount(tid,name,rid);
    }

    //添加我的餐厅
    public void addmy_res(int tid,String name,int rid) {
        qiantaiDao.addmy_res(tid,name,rid);
    }

    //查找是否存在该旅店
    public int getmy_holCount(int tid,String name,int hid) {
        return qiantaiDao.getmy_holCount(tid,name,hid);
    }

    //添加我的旅店
    public void addmy_hol(int tid,String name,int hid) {
        qiantaiDao.addmy_hol(tid,name,hid);
    }

    //路线对应的我的旅店
    public List<hotel> getmy_hol(int tid) {
        return qiantaiDao.getmy_hol(tid);
    }

    //路线对应的我的餐厅
    public List<restaurant> getmy_res(int tid) {
        return qiantaiDao.getmy_res(tid);
    }

    //路线对应的我的旅店（微信）
    public List<hotel> getmy_hol_wx(String uid,String my_rode) {
        return qiantaiDao.getmy_hol_wx(uid,my_rode);
    }

    //路线对应的我的餐厅（微信）
    public List<restaurant> getmy_res_wx(String uid,String my_rode) {
        return qiantaiDao.getmy_res_wx(uid,my_rode);
    }

    //拿到用户选择的景点数目
    public int gettouristSpotCount(String uid,String title) {
        return qiantaiDao.gettouristSpotCount(uid, title);
    }

    //拿到用户选择的景点名称
    public String[] gettouristSpotName(String uid,String title) {
        String[] spot= qiantaiDao.gettouristSpotName(uid,title);
        return spot;
    }

    //拿到用户所选的景点经纬度（计算多对多距离矩阵）
    public String gettouristSpotPosition(String[] spotname){
        String form="";
        for (int i = 0; i <spotname.length ; i++) {
            form=form+qiantaiDao.gettouristSpotLat(spotname[i]);
            form = form+",";
            form=form+qiantaiDao.gettouristSpotLong(spotname[i]);
            if ( i <spotname.length-1){
                form = form+";";
            }
        }
        return form;
    }

    //添加新的我的路线(最优路线和时间)
    public void addnewtourist(String uid,String title,String tourist,String walk_time) {
        int num=qiantaiDao.getnew_tourist(uid,title);
        if (num==0){
            qiantaiDao.addnewtourist(uid,title,tourist,walk_time);
        }
    }

    //拿到用户所选的景点经纬度（计算路线相邻景点的步行时间）
    public String getoneSpotPosition(String spotname){
        String from="";
        from = from + qiantaiDao.gettouristSpotLat(spotname);
        from = from+",";
        from=from+qiantaiDao.gettouristSpotLong(spotname);
        return from;
    }

    //根据景点数组拿到id
    public String get_spotid(String spotname){
        return qiantaiDao.getspotid(spotname);
    }

    //拿到GreedTourist的经纬度(LAT)
    public String[] getGreedtouristLat(String[] spot){
        String Lat[]=null;
        for (int i = 0; i <spot.length ; i++) {
            Lat[i]=qiantaiDao.gettouristSpotLat(spot[i]);
        }
        return Lat;
    }

    //拿到GreedTourist的经纬度(LONG)
    public String[] getGreedtouristLong(String[] spot){
        String Long[]=null;
        for (int i = 0; i <spot.length ; i++) {
            Long[i]=qiantaiDao.gettouristSpotLat(spot[i]);
        }

        return Long;
    }

    //删除路线(my_tourist)
    public void getDelete_tourist(String uid,String title){
        int one_tourist_num=qiantaiDao.getnew_tourist(uid,title);
        for (int i=0;i<one_tourist_num-1;i++){
            qiantaiDao.getDelete_tourist(uid, title);
        }
        qiantaiDao.getDelete_tourist(uid,title);
    }

    //删除路线（tourist_route）
    public void getDelete_tourist_route(String uid,String title){
        qiantaiDao.getDelete_tourist_route(uid, title);
    }

    //删除（my_res,my_hol)
    public void getDelete_my_res(String tid){
        qiantaiDao.getDelete_my_res(tid);
    }
    public void getDelete_my_hol(String tid){
        qiantaiDao.getDelete_my_hol(tid);
    }

    //拿到tid
    public String [] get_tid(String uid,String title){
        return qiantaiDao.get_tid(uid,title);
    }
}

